package com.ruoyi.system.api.service.impl;

import java.util.*;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.OkHttpUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.*;
import com.ruoyi.system.api.domain.dto.AddPhoneReportDto;
import com.ruoyi.system.api.mapper.*;
import com.ruoyi.system.api.service.CcService;
import com.ruoyi.system.api.service.IInterfaceOperationLogService;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.api.service.IStPhoneReportService;
import com.ruoyi.common.core.text.Convert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils;

/**
 * 电话解决报告Service业务层处理
 *
 * @author ruoyi
 * @date 2020-03-03
 */
@Service
public class StPhoneReportServiceImpl implements IStPhoneReportService {

    private static final Logger log = LoggerFactory.getLogger(StPhoneReportServiceImpl.class);

    /**
     * 配置文件
     */
    @Autowired
    private Global global;

    /**
     * 电话解决报告表
     */
    @Autowired
    private StPhoneReportMapper stPhoneReportMapper;

    /**
     * 工程师FSE计划详情表
     */
    @Autowired
    private PlanDetailsMapper planDetailsMapper;

    /**
     * 报告与备件的关系表
     */
    @Autowired
    private StReportPortMapper reportPortMapper;

    /**
     * 服务通知的子表服务表与报告关联表
     */
    @Autowired
    private ReportInfoMapper reportInfoMapper;

    /**
     * 附件表
     */
    @Autowired
    private AnnexMapper annexMapper;

    /**
     * 接口调用日志
     */
    @Autowired
    private IInterfaceOperationLogService iInterfaceOperationLogService;

    /**
     * 调用CC接口service
     */
    @Autowired
    private CcService ccService;

    @Autowired
    private ServiceDetailsMapper serviceDetailsMapper;




    /**
     * 查询电话解决报告
     *
     * @param id 电话解决报告ID
     * @return 电话解决报告
     */
    @Override
    public StPhoneReport selectStPhoneReportById(Long id) {
        return stPhoneReportMapper.selectStPhoneReportById(id);
    }

    /**
     * 查询电话解决报告列表
     *
     * @param stPhoneReport 电话解决报告
     * @return 电话解决报告
     */
    @Override
    public List<StPhoneReport> selectStPhoneReportList(StPhoneReport stPhoneReport) {
        return stPhoneReportMapper.selectStPhoneReportList(stPhoneReport);
    }

    /**
     * 新增电话解决报告
     *
     * @param stPhoneReport 电话解决报告
     * @return 结果
     */
    @Override
    public int insertStPhoneReport(StPhoneReport stPhoneReport) {
        stPhoneReport.setCreateTime(DateUtils.getNowDate());
        return stPhoneReportMapper.insertStPhoneReport(stPhoneReport);
    }

    /**
     * 修改电话解决报告
     *
     * @param stPhoneReport 电话解决报告
     * @return 结果
     */
    @Override
    public int updateStPhoneReport(StPhoneReport stPhoneReport) {
        stPhoneReport.setUpdateTime(DateUtils.getNowDate());
        return stPhoneReportMapper.updateStPhoneReport(stPhoneReport);
    }

    /**
     * 删除电话解决报告对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteStPhoneReportByIds(String ids) {
        return stPhoneReportMapper.deleteStPhoneReportByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除电话解决报告信息
     *
     * @param id 电话解决报告ID
     * @return 结果
     */
    @Override
    public int deleteStPhoneReportById(Long id) {
        return stPhoneReportMapper.deleteStPhoneReportById(id);
    }

    /**
     * 添加电话解决报告
     *
     * @param phoneReportDto
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-02 13:56
     */
    @Override
    public ResponseWithData<?> addPhoneReport(AddPhoneReportDto phoneReportDto) {
        // 参数校验 start
        if (phoneReportDto.getPlanId() == null) {
            return new ResponseWithData<>().error("planId cannot be empty！");
        }
        if (phoneReportDto.getNoticeId() == null) {
            return new ResponseWithData<>().error("noticeId cannot be empty！");
        }
        if (phoneReportDto.getEnginnerId() == null) {
            return new ResponseWithData<>().error("enginnerId cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getServiceNo())) {
            return new ResponseWithData<>().error("serviceNo cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getProblem())) {
            return new ResponseWithData<>().error("problem cannot be empty！");
        }
        if (null == phoneReportDto.getOrderReceivedDate()) {
            return new ResponseWithData<>().error("orderReceivedDate cannot be empty！");
        }
        if (null == phoneReportDto.getCallingStartDate()) {
            return new ResponseWithData<>().error("callingStartDate cannot be empty！");
        }
        if (null == phoneReportDto.getCallingEndDate()) {
            return new ResponseWithData<>().error("callingEndDate cannot be empty！");
        }
        if (phoneReportDto.getCallingStartDate().getTime() > phoneReportDto.getCallingEndDate().getTime()) {
            return new ResponseWithData<>().error("callingStartDate cannot be greater than callingEndDate！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getServiceResults())) {
            return new ResponseWithData<>().error("serviceResults cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getHelpId())) {
            return new ResponseWithData<>().error("helpId cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getFseName())) {
            return new ResponseWithData<>().error("fseName cannot be empty！");
        }
        // 参数校验 end


        // 数据入库 strat

        ReportInfo reportInfo = new ReportInfo();
        if (phoneReportDto.getId() != null) {
            phoneReportDto.setUpdateTime(new Date());
            phoneReportDto.setUpdateBy(phoneReportDto.getEnginnerId() + "");
            stPhoneReportMapper.updateAddPhoneReportDto(phoneReportDto);
            reportInfo = reportInfoMapper.selectStReportInfoByServiceNoAndEnginnerIdAndRelServiceNoAndRelPlanIdAndBatchType(phoneReportDto.getServiceNo(), phoneReportDto.getEnginnerId(), "6", "st_phone_report", phoneReportDto.getId());
            reportInfo.setServiceResult(phoneReportDto.getServiceResults());
            reportInfo.setUpdateTime(new Date());
            reportInfo.setUpdateBy(phoneReportDto.getEnginnerId() + "");
            reportInfo.setEnginnerId(phoneReportDto.getEnginnerId());
            reportInfo.setFseName(phoneReportDto.getFseName());
            reportInfoMapper.updateStReportInfo(reportInfo);
        } else {
            // 验证是否存在已完成的报告（服务报告或电话解决报告）
            List<ReportInfo> datas = reportInfoMapper.selectFinishStReportInfoByServiceNo(phoneReportDto.getId(), phoneReportDto.getServiceNo());
            if (StringUtils.isNotEmpty(datas)) {
                return new ResponseWithData<>().error("已存在已完成报告");
            }
            phoneReportDto.setCreateTime(new Date());
            phoneReportDto.setCreateBy(phoneReportDto.getEnginnerId() + "");
            phoneReportDto.setDelFlag("0");
            phoneReportDto.setSyncFlag("0");
            stPhoneReportMapper.insertAddPhoneReportDto(phoneReportDto);

            // 电话解决报告信息保存到主表 st_report_info
            reportInfo.setServiceNo(phoneReportDto.getServiceNo());
            reportInfo.setEnginnerId(phoneReportDto.getEnginnerId());
            reportInfo.setPlanId(phoneReportDto.getPlanId());
            reportInfo.setRelServiceNo(6L);
            reportInfo.setRelPlanId("st_phone_report");
            reportInfo.setBatchType(phoneReportDto.getId());
            reportInfo.setDelFlag("0");
            reportInfo.setCreateTime(new Date());
            reportInfo.setCreateBy(phoneReportDto.getEnginnerId() + "");
            reportInfo.setNoticeId(phoneReportDto.getNoticeId());
            reportInfo.setSyncFlag("0");
            reportInfo.setFseName(phoneReportDto.getFseName());
            reportInfo.setServiceResult(phoneReportDto.getServiceResults());
            reportInfoMapper.insertStReportInfo(reportInfo);


        }
        // 更新备件关联信息
        reportPortMapper.updatePhoneReportPortByHelpIdAndServiceNo(phoneReportDto.getId(), phoneReportDto.getHelpId(), phoneReportDto.getServiceNo());
        // 数据入库 end
        deletePhoneReportPort(phoneReportDto);
        return new ResponseWithData<>().success(reportInfo).code(200);
    }

    private void deletePhoneReportPort(AddPhoneReportDto phoneReportDto) {
        List<StReportPort> stReportPorts = reportPortMapper.selectStReportPortListByServiceNoAndHelpIdAndPortType(phoneReportDto.getServiceNo(), phoneReportDto.getHelpId(), "2");
        for (StReportPort stReportPort : stReportPorts) {
            ccService.deleteCCParts(stReportPort.getPid());
        }
    }

    /**
     * 修改电话解决报告
     *
     * @param phoneReportDto
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/5 10:33 上午
     */
    @Override
    public ResponseWithData<?> updatePhoneReport(AddPhoneReportDto phoneReportDto) {
        // 参数校验 start
        if (phoneReportDto.getId() == null) {
            return new ResponseWithData<>().error("id cannot be empty！");
        }
        if (phoneReportDto.getPlanId() == null) {
            return new ResponseWithData<>().error("planId cannot be empty！");
        }
        if (phoneReportDto.getNoticeId() == null) {
            return new ResponseWithData<>().error("noticeId cannot be empty！");
        }
        if (phoneReportDto.getEnginnerId() == null) {
            return new ResponseWithData<>().error("enginnerId cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getServiceNo())) {
            return new ResponseWithData<>().error("serviceNo cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getProblem())) {
            return new ResponseWithData<>().error("problem cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getProblem())) {
            return new ResponseWithData<>().error("problem cannot be empty！");
        }
        if (null == phoneReportDto.getOrderReceivedDate()) {
            return new ResponseWithData<>().error("orderReceivedDate cannot be empty！");
        }
        if (null == phoneReportDto.getCallingStartDate()) {
            return new ResponseWithData<>().error("callingStartDate cannot be empty！");
        }
        if (null == phoneReportDto.getCallingEndDate()) {
            return new ResponseWithData<>().error("callingEndDate cannot be empty！");
        }
        if (phoneReportDto.getCallingStartDate().getTime() > phoneReportDto.getCallingEndDate().getTime()) {
            return new ResponseWithData<>().error("callingStartDate cannot be greater than callingEndDate！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getServiceResults())) {
            return new ResponseWithData<>().error("serviceResults cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getHelpId())) {
            return new ResponseWithData<>().error("helpId cannot be empty！");
        }
        if (StringUtils.isEmpty(phoneReportDto.getFseName())) {
            return new ResponseWithData<>().error("fseName cannot be empty！");
        }
        // 参数校验 end

        // 数据入库 strat

        // 1、保存电话解决报告信息
        phoneReportDto.setUpdateTime(new Date());
        phoneReportDto.setUpdateBy(phoneReportDto.getEnginnerId() + "");
        stPhoneReportMapper.updateAddPhoneReportDto(phoneReportDto);

        ReportInfo reportInfo = reportInfoMapper.selectStReportInfoByBatchType(phoneReportDto.getId(), "6");
        reportInfo.setServiceResult(phoneReportDto.getServiceResults());
        reportInfo.setUpdateBy(phoneReportDto.getEnginnerId() + "");
        reportInfo.setUpdateTime(new Date());
      //  reportInfo.setEnginnerId(phoneReportDto.getEnginnerId());
      //  reportInfo.setFseName(phoneReportDto.getFseName());
        reportInfoMapper.updateStReportInfo(reportInfo);

        // 2、更新备件关联信息

        reportPortMapper.updatePhoneReportPortByHelpIdAndServiceNo(phoneReportDto.getId(), phoneReportDto.getHelpId(), phoneReportDto.getServiceNo());

        // 3、更新主表的服务结果
        if (StringUtils.isNotEmpty(phoneReportDto.getServiceResults())) {
            reportInfoMapper.updateServiceResults(Long.parseLong(phoneReportDto.getServiceResults()), "st_phone_report", phoneReportDto.getId());
        }

        // 数据入库 end
        deletePhoneReportPort(phoneReportDto);
        return new ResponseWithData<>().success(phoneReportDto).code(200);
    }

    /**
     * 查看电话解决报告
     *
     * @param id
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/5 10:30 上午
     */
    @Override
    public ResponseWithData<?> detailPhoneReport(Long id) {
        ReportInfo reportInfo = reportInfoMapper.selectStReportInfoById(id);
        if (null != reportInfo) {
            StPhoneReport stPhoneReport = stPhoneReportMapper.selectStPhoneReportById(reportInfo.getBatchType());
            reportInfo.setReportInfo(stPhoneReport);
        }
        return new ResponseWithData<>().success(reportInfo).code(200);
    }

    /**
     * 提交电话解决报告
     *
     * @param id 电话解决报告主键ID
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/5 2:48 下午
     */
    @Override
    public ResponseWithData<?> phoneSolveSubmit(Long id, Long enginnerId) {
        if (null == id) {
            return new ResponseWithData<>().error().msg("id cannot be empty");
        }
        if (null == enginnerId) {
            return new ResponseWithData<>().error().msg("enginnerId cannot be empty");
        }

        // 查寻电话解决报告基本信息
        StPhoneReport stPhoneReport = stPhoneReportMapper.selectStPhoneReportById(id);
        ReportInfo reportInfo = reportInfoMapper.selectStReportInfoByBatchType(id, "6");

        // 判断非本人提交报告
        if (!(enginnerId+"").equals(reportInfo.getEnginnerId()+"")) {
            String name=reportInfo.getFseName();
            return new ResponseWithData<>().error().msg("你不能提交"+name+"的报告, 如需提交请联系"+name);
        }

        if (null == stPhoneReport || null == reportInfo) {
            return new ResponseWithData<>().error().msg("电话解决报告不存在");
        }

        if ("1".equals(stPhoneReport.getServiceResults())) {
            // 在非实习生的工作日志未关联报告的情况下不可添加已完成的电话解决报告
            int logs = reportInfoMapper.selectLogCountByServiceNo(stPhoneReport.getServiceNo());
            if (logs > 0) {

                List<String> fseNameList= reportInfoMapper.selectLogCountByServiceNoFseName(stPhoneReport.getServiceNo());
               if(fseNameList.size()>0) {
                   StringBuffer nameList = new StringBuffer();
                   for (String name : fseNameList) {
                       nameList.append(name + "，");
                   }
                   String fseName = nameList.deleteCharAt(nameList.length() - 1).toString();
                   return new ResponseWithData<>().error().msg(fseName + "有未关联报告的日志，不可提交已完成的报告");
               }
            }

            // 20200528 提交已完成时 校验是否存在草稿状态的服务报告
            ReportInfo info = new ReportInfo();
            info.setServiceNo(reportInfo.getServiceNo());
          //  info.setPlanId(reportInfo.getPlanId());
            info.setSyncFlag("0");
        //    info.setRelServiceNo(1L); //服务报告
            info.setDelFlag("0");
            List<ReportInfo> plist = reportInfoMapper.selectStReportInfoList(info);
            if (!ObjectUtils.isEmpty(plist)) {
                //不能有任何草稿的报告
                int i = 0;
                for (ReportInfo reportInfo1 : plist) {
                    i++;
                    if (i >= 2) {
                        return new ResponseWithData<>().error().msg("存在未提交的报告，不可提交已完成电话解决报告");
                    }
                    if (StringUtils.equals("6", reportInfo1.getRelServiceNo().toString())) {
                        if (!StringUtils.equals(id.toString(), reportInfo1.getBatchType().toString())) {
                            return new ResponseWithData<>().error().msg("存在未提交的电话解决报告，不可提交已完成电话解决报告");
                        }
                    } else {
                        return new ResponseWithData<>().error().msg("存在未提交的报告，不可提交已完成电话解决报告");
                    }
                }
            }
        }

        if ("1".equals(reportInfo.getSyncFlag())) {
            return new ResponseWithData<>().error().msg("此电话解决报告已提交过");
        }

        Map<String, String> params = new HashMap<>();
        // 唯一主键
        params.put("report_guid", reportInfo.getId().toString());
        // Service号
        params.put("service_no", reportInfo.getServiceNo());
        // 提交的工程师ID
        params.put("enginner_id", enginnerId + "");
        // 故障
        params.put("problem", stPhoneReport.getProblem());
        // 工作过程
        params.put("action_taken", stPhoneReport.getActionTaken());
        // 工程师建议
        params.put("engineers_advis", stPhoneReport.getEngineersAdvis());
        // 接收任务时间
        params.put("order_received_date", DateUtils.parseDateToStrEmpty(DateUtils.YYYY_MM_DD_HH_MM_SS, stPhoneReport.getOrderReceivedDate()));
        // 电话开始时间
        params.put("calling_start_date", DateUtils.parseDateToStrEmpty(DateUtils.YYYY_MM_DD_HH_MM_SS, stPhoneReport.getCallingStartDate()));
        // 电话结束时间
        params.put("calling_end_date", DateUtils.parseDateToStrEmpty(DateUtils.YYYY_MM_DD_HH_MM_SS, stPhoneReport.getCallingEndDate()));
        // 电话解决时间
        params.put("equivalent_to_huors", stPhoneReport.getEquivalentToHuors() + "");
        // 结果
        params.put("result", stPhoneReport.getResult());
        // 服务结果
        params.put("service_results", stPhoneReport.getServiceResults());
        // 工作类型
        params.put("WorkType", stPhoneReport.getWorkType());
        // 关注说明
        params.put("remark", StringUtils.isEmpty(stPhoneReport.getConcernReason()) ? "" : stPhoneReport.getConcernReason());
        // 中断类型
        params.put("suspend_type", stPhoneReport.getSuspendType());
        // 中断子类型
        params.put("suspend_subtype", stPhoneReport.getSuspendSonType());
        // 工作中断原因
        params.put("work_suspend_reason", stPhoneReport.getWorkSuspendReason());
        params.put("service_type", "0,0,0,0,0");


        // 查询电话解决报告备件信息
        List<StReportPort> stReportPorts = reportPortMapper.selectStReportPortListByServiceNoAndHelpIdAndPortType(stPhoneReport.getServiceNo(), stPhoneReport.getHelpId(), "2");
        if (null != stReportPorts) {
            List<Map<String, Object>> reportPortsParams = new ArrayList<>();
            for (StReportPort stReportPort : stReportPorts) {
                Map<String, Object> reportPortParams = new HashMap<>();
                // 备件号
                reportPortParams.put("part_number", stReportPort.getPartNumber());
                // 借贷单号
                reportPortParams.put("loan_number", stReportPort.getLoanNumber());
                // 备件序列号

                reportPortParams.put("part_serial_number", StringUtils.isEmpty(stReportPort.getPartSerialNumber()) ? "" : stReportPort.getPartSerialNumber());
                // 备件名称
                reportPortParams.put("part_name", stReportPort.getPartName());
                // QTY数量  备件数量
                reportPortParams.put("qty_count", stReportPort.getQtyCount());
                // Price单价
                reportPortParams.put("price", stReportPort.getPrice());
                // Price总价
                reportPortParams.put("totalprice", stReportPort.getTotalprice());
                // 更换类型 备件类型
                reportPortParams.put("part_type", StringUtils.isEmpty(stReportPort.getPartType())? "" : stReportPort.getPartType());
                // 备注
                reportPortParams.put("remark", StringUtils.isEmpty(stReportPort.getRemark()));
                // 坏件序列号
                reportPortParams.put("Damage_serial_number", StringUtils.isEmpty(stReportPort.getDamageSerialNumber()) ? "" : stReportPort.getDamageSerialNumber());

                // 坏件图片
                List<Annex> annexes = annexMapper.selectAnnexListByHelpIdAndServiceNo(stReportPort.getServiceNo(), stReportPort.getAnnexHelpId());
                if (null != annexes) {
                    String path="";
                    for (Annex annex : annexes) {
                        path=
                                //global.getPicUrl() +
                                        annex.getFilePath();
                    }
                    reportPortParams.put("Damage_pic", path);
                } else {
                    reportPortParams.put("Damage_pic", "");
                }

                // 坏件是否还库
                reportPortParams.put("IsOutWarranty", StringUtils.isEmpty(stReportPort.getIsOutWarranty()) ? "" : stReportPort.getIsOutWarranty());
                // 备件状态变更说明
                reportPortParams.put("StatusChange", StringUtils.isEmpty(stReportPort.getStatusChange()) ? "" : stReportPort.getStatusChange());
                // 备件状态变更备注
                reportPortParams.put("ChangeRemark", StringUtils.isEmpty(stReportPort.getChangeRemark()) ? "" : stReportPort.getChangeRemark());
                // 备件编号
                reportPortParams.put("PID", stReportPort.getPid());

                reportPortsParams.add(reportPortParams);
            }
            params.put("part_data", JSON.toJSONString(reportPortsParams));
        } else {
            params.put("part_data", "[]");
        }

        // 请求CC接口 提交电话解决报告
        String response = ccService.phoneSolveSubmithandle(params);

        /** 如果调用接口异常直接返回 */
        if (null == response) {
            return new ResponseWithData().error().msg("提交电话解决报告失败 调用CC端提交电话解决报告接口发生异常").code(202);
        }

        JSONObject jsonObject = JSONObject.parseObject(response);
        String status = jsonObject.getString("status");
        if ("1".equals(status)) {

            String rptNo = "";
            try {
                JSONArray record = jsonObject.getJSONArray("record");
                if (record != null && record.size() > 0) {
                    rptNo = record.getJSONObject(0).getString("rpt_no");
                }
            } catch (Exception e) {
                log.error("程序异常", e.getMessage());
            }

            // 提交成功 ，更新同步状态
            ReportInfo info = new ReportInfo();
            info.setId(reportInfo.getId());
            info.setSyncFlag("1");
            info.setSyncTime(new Date());
            info.setReportNo(rptNo);
            reportInfoMapper.updateStReportInfo(info);

            stPhoneReportMapper.updateCcSyncStatusById(stPhoneReport.getId());
            reportPortMapper.updateCcSyncStatusByReportId(stPhoneReport.getId());

            // 电话解决报告提交成功更新st_plan_details状态 （已完成）
            if ("1".equals(reportInfo.getServiceResult())) {
                ServiceDetails serviceDetails = new ServiceDetails();
                serviceDetails.setFseId(enginnerId + "");
                serviceDetails.setState(4L);
                serviceDetails.setServiceNoticeId(reportInfo.getNoticeId());
                serviceDetailsMapper.updateMyServiceDetails(serviceDetails);

                //TODO 是否需要更新状态  电话解决不更新计划状态
                //PlanDetails planDetails = new PlanDetails();
                //planDetails.setUpdateBy(enginnerId + "");
                //planDetails.setUpdateTime(new Date());
                //planDetails.setState("4");
                //planDetails.setFillInLog("1");
                //planDetails.setId(reportInfo.getPlanId());
                //planDetailsMapper.updateStPlanDetails(planDetails);

                //电话解决报告中不需要上门进行删除操作  st_service_details  ,st_plan_details
//                ServiceDetails serviceDetailsSearch = new ServiceDetails();
//                serviceDetailsSearch.setFseId(enginnerId + "");
//                serviceDetailsSearch.setServiceNoticeId(reportInfo.getNoticeId());
//                List<ServiceDetails> serviceDetailsList= serviceDetailsMapper.selectServiceDetailsList(serviceDetailsSearch);
//                ServiceDetails curentServiceDetails=serviceDetailsList.get(0);
//
//                PlanDetails planDetails1=planDetailsMapper.selectStPlanDetailsById(new Long(curentServiceDetails.getUpdateBy()));
//                 if("1".equals(planDetails1.getState()) && "0".equals(planDetails1.getSignIn())){
//                     planDetailsMapper.deleteStPlanDetailsById(new Long(curentServiceDetails.getUpdateBy()));
//                 }
//                PlanDetails planDetails2=new PlanDetails();
//                planDetails2.setFseId(enginnerId+"");
//                planDetails2.setServiceNoticeId( reportInfo.getNoticeId());
//                List<PlanDetails> planDetails3= planDetailsMapper.selectStPlanDetailsList(planDetails2);
//                PlanDetails currentPlanDetails=planDetails3.get(0);
//
//                curentServiceDetails.setUpdateBy(currentPlanDetails.getId()+"");
//                serviceDetailsMapper.updateMyServiceDetails(curentServiceDetails);

            }
            for (StReportPort reportPort : stReportPorts) {
                ccService.deleteCCParts(reportPort.getPid());
            }


            return new ResponseWithData().success().msg("提交验收报告成功").code(200);
        } else if ("2".equals(status)) {
            String message = jsonObject.getString("message");
            return new ResponseWithData().error().msg(message).code(201);
        } else {
            return new ResponseWithData().error().msg("提交电话解决报告失败 调用CC端提交电话解决报告接口发生异常").code(201);
        }
    }
}
